package ControleDiversas;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import JBCD.MetodoConexao;
import VisaoControleAcademico.MatriculaView;
import VisaoControleAcademico.NovaTurma;
import VisaoControleAcademico.PainelPrincipal;

public class MetodoDePesquisaCPA {
	static Vector<String> listaP;
	static String valor1;

	public static void pesquisar() {

		PainelPrincipal.JComCursoP.removeAllItems();
		try {
			Class.forName("org.postgresql.Driver");
		} catch (ClassNotFoundException ex) {
			Logger.getLogger(MetodoDePesquisaCPA.class.getName()).log(
					Level.SEVERE, null, ex);
		}
		MetodoConexao.conctarBanco();
		try {
			ResultSet resultado_RS = MetodoConexao.coneck.executeQuery("SELECT * FROM curso ORDER BY nome");
			while (resultado_RS.next()) {
				PainelPrincipal.JComCursoP.addItem(resultado_RS.getString("nome").trim());
				
			}
			MetodoConexao.con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public static void pesquisarNovaTurma(){
		NovaTurma.jcCurso.removeAllItems();
		MetodoConexao.conctarBanco();
		try {
			ResultSet resultado_RS = MetodoConexao.coneck.executeQuery("SELECT * FROM curso ORDER BY nome");
			while (resultado_RS.next()) {
				NovaTurma.jcCurso.addItem(resultado_RS.getString("nome").trim());
						}
			MetodoConexao.con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void nadoJcomBomboxTurma() {

		MetodoConexao.conctarBanco();
		try {
			ResultSet RS = MetodoConexao.coneck.executeQuery("SELECT * FROM professor ORDER BY nome");
			listaP = new Vector<String>();
			valor1 = (String) NovaTurma.jcCurso.getSelectedItem();
			if (valor1 != null) {
				while (RS.next()) {
					if (valor1.equals(RS.getString("curso").trim())) {
						listaP.add(RS.getString("nome").trim());
					}

				}
			}
			NovaTurma.listaProfessor.setListData(listaP);
			MetodoConexao.con.close();
		} catch (SQLException ef) {
			ef.printStackTrace();
		}

	}
	public static void atualizarJcombomboxMatricula() {
		MetodoConexao.conctarBanco();
		MatriculaView.areaMatriCont.setText(null);
		try {
			ResultSet RS = MetodoConexao.coneck.executeQuery("SELECT * FROM curso");
		String	valorc = (String) MatriculaView.jcomCursoMatri.getSelectedItem();
		if (valorc != null) {
			while (RS.next()) {
				if (valorc.equals(RS.getString("nome").trim())) {
					MatriculaView.areaMatriCont.setText(RS.getString("cronograma").trim());
				}	
				}
			
		}
		} catch (SQLException ef) {
			ef.printStackTrace();
		}
		
		
		
	}
	
	
}
